#.hack CMP parser

import os, sys
from Sanae3D.lib.ModelObject import Model3D
from Sanae3D.lib.StructReader import StructReader

class dotHack_cmp(Model3D):
    
    def __init__(self, obj3D=None, outFile=None, inFile=None):
        
        super(dotHack_cmp,self).__init__("CMP")
        self.obj3D = obj3D
        self.inFile = inFile
        self.outFile = outFile
        self.meshType = -1
        
    def parse_file(self):
        '''Main parser method. Can be replaced'''
        
        self.inFile.seek(13672)
        temp = "obj"
        self.create_object(temp)
        for i in range(46):
            vx, vy, vz=  self.inFile.read_float(3)
            nx, ny, nz = self.inFile.read_float(3)
            self.create_vertex(temp, i)
            self.add_coords(temp, i, [vx, vy, vz])
        
def read_file(path):
    '''Read the file'''
    
    openFile = StructReader(open(path, 'rb'))
    obj = dotHack_cmp(inFile=openFile)
    obj.parse_file()
    openFile.close()
    return obj

def write_file(path):
    
    pass

def definitions():
    '''Return the header, extension, and a description of the format'''
    
    return "", "CMP", "dotHack_cmp"

if __name__ == '__main__':
    
    file1 = "aoyun_huoju.ltb"
    file2 = "aoyun_weapon_jx.ltb"
    file3 = "js_ys_Rweapon008b.ltb"
    file4 = "missionitem027.ltb"
    obj = read_file(file2)